package com.wooming.studentinfosystem.controller;

import com.wooming.studentinfosystem.dto.StudentSearchDTO;
import com.wooming.studentinfosystem.service.impl.StudentSearchService;
import com.wooming.studentinfosystem.util.PageResult;
import com.wooming.studentinfosystem.util.Result;
import com.wooming.studentinfosystem.vo.StudentVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * Controller层: 学生信息搜索
 *
 * @author Wooming
 */
@RestController
@RequestMapping("/api/students")
public class StudentSearchController {

    @Autowired
    private StudentSearchService studentSearchService;

    @PostMapping("/search")
    public Result<PageResult<StudentVO>> searchStudents(@RequestBody StudentSearchDTO params) {
        // 参数校验
        if (params.getPageSize() > 100) {
            return Result.error(400, "每页数量不能大于100");
        }
        return Result.success(studentSearchService.searchStudents(params));
    }
}
